package com.yidu.best.basicSetup.securityset.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.best.basicSetup.securityset.domain.Security;
import com.yidu.best.basicSetup.securityset.domain.SecurityVo;
import com.yidu.best.basicSetup.securityset.service.SecurityService;

@Controller
@RequestMapping("/SecurityController/")
public class SecurityController {
	@Autowired
	public SecurityService securityService;
	
	/**
	 * 跳转页面到securityList
	 * @return
	 */
	@RequestMapping(value = "securityList",method = RequestMethod.GET)
	public String jumpSecurity() {
		System.err.println("跳转到首页");
		return "sys/Security/SecurityList";
	}
	
	
	/**
	 * 分页查询
	 * @param securityVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "securitys",method = RequestMethod.GET)
	public  Map<String,Object> selectSecurity(SecurityVo securityVo){
		System.out.println(securityVo);
		Map<String,Object> map = new HashMap<String, Object>();
		map = securityService.findSecurity(securityVo);

		return map ;
	}
	/**
	 * 添加方法
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "security",method = RequestMethod.POST)
	public boolean addSecurity(Security security) {
		int rs = securityService.addSecurity(security);
		if(rs == 1) {
			return true;
		}
		return false;
	}
	
	/**
	 * 修改方法
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "security",method = RequestMethod.PUT)
	public boolean updateSecurity(Security security) {
		//调用业务层修改方法
		int rs = securityService.updateSecurity(security);
		//如何rs=1 则修改成功
		if(rs==1) {
			return true;
		}else {
			return false;
		}
		
	}
	
	/**
	 * 删除
	 * @param securityIds
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "security/{securityIds}", method = RequestMethod.DELETE)
	public boolean deleteSecurity(@PathVariable("securityIds")String securityIds ) {
		System.out.println("进入删除方法");
		//定义变量
		int rs=0;
		//定义数组接受前台返回的字符串数组 将,去掉
        String[] securityId = securityIds.split(",");
        //将接收的数组遍历
        for (int i = 0; i < securityId.length; i++) {
        	//调用业务层方法
        	rs = securityService.deleteSecurity(securityId[i]);
        }
        System.out.println(rs);
        if(rs==1) {
        	return true;
        }
     
        return false;
	}
}
